package net.runman.service;


import net.runman.mapper.UserMapper;
import net.runman.model.User;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserService {

	@Autowired
	private UserMapper userMapper;

	@Transactional(rollbackFor = RuntimeException.class)
	public int addUser(User userToAdd) {
		return userMapper.insert(userToAdd);
	}

	@Cacheable(value = "userCache", key ="#root.method.name.concat('-').concat(#userId)")
	public User getUser(int userId) {
		return userMapper.selectByPrimaryKey(userId);
	}
}